﻿//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Text;
//using Castle.Core.Resource;
//using Castle.MicroKernel;
//using Castle.Windsor;
//using Castle.Windsor.Configuration;
//using Castle.Windsor.Configuration.Interpreters;
//using Castle.Windsor.Installer;

//namespace JML.Core.DI
//{
//    public class BinsorContainer : WindsorContainer
//    {
//        private bool _isDisposed = false;

//        public BinsorContainer()
//        {
//        }
//        public BinsorContainer(IWindsorContainer parent)
//            : base(parent, new XmlInterpreter(new StaticContentResource("<configuration/>")))
//        {
//        }
//        public BinsorContainer(string fileName)
//            : this(fileName, null)
//        {
//        }
//        public BinsorContainer(string fileName, IEnvironmentInfo enviroment)
//            : base(new DefaultKernel(), _CreateInterpreter(fileName, enviroment))
//        {
//            if (_IsBoo(fileName)) RunInstaller();
//            else
//            {
//                _InitalizeFromConfigurationSource(new XmlInterpreter(fileName), enviroment);
//            }
//        }
//        public BinsorContainer(IConfigurationInterpreter interpreter)
//            : this(interpreter, null)
//        {
//        }
//        public BinsorContainer(IConfigurationInterpreter interpreter, IEnvironmentInfo enviroment)
//        {
//            _InitalizeFromConfigurationSource(interpreter, enviroment);
//        }


//        public bool IsDisposed
//        {
//            get { return _isDisposed; }
//        }

//        public override T Resolve<T>(string key)
//        {
//            _VerifyThatContainerIsNotDisposed();
//            return base.Resolve<T>(key);
//        }
//        public override object Resolve(string key)
//        {
//            _VerifyThatContainerIsNotDisposed();
//            return base.Resolve(key);
//        }
//        public override object Resolve(string key, Type service)
//        {
//            _VerifyThatContainerIsNotDisposed();
//            return base.Resolve(key, service);
//        }
//        public override object Resolve(Type service)
//        {
//            _VerifyThatContainerIsNotDisposed();
//            return base.Resolve(service);
//        }

//        public override void Dispose()
//        {
//            _isDisposed = true;

//            base.Dispose();
//        }


//        private static IComponentsInstaller _CreateInterpreter(string fileName, IEnvironmentInfo enviroment)
//        {
//            if (_IsBoo(fileName)) return new BooComponentInstaller(fileName, enviroment);

//            return new DefaultComponentInstaller();
//        }
//        private static bool _IsBoo(string fileName)
//        {
//            string[] binsorExtensions = new string[] { ".boo", ".binsor", };
//            string configFileExtension = Path.GetExtension(fileName);

//            foreach (string extension in binsorExtensions)
//            {
//                if (configFileExtension.Equals(extension, StringComparison.InvariantCultureIgnoreCase))
//                    return true;
//            }
//            return false;
//        }
//        private void _InitalizeFromConfigurationSource(IConfigurationInterpreter interpreter, IEnvironmentInfo enviroment)
//        {
//            if (enviroment != null) interpreter.EnvironmentName = enviroment.GetEnvironmentName();

//            interpreter.ProcessResource(interpreter.Source, Kernel.ConfigurationStore);
//            RunInstaller();
//        }
//        private void _VerifyThatContainerIsNotDisposed()
//        {
//            if (_isDisposed) throw new ObjectDisposedException("The container has been disposed!");
//        }
//    }

//}
